#include "virtualkeyboarddelegate.h"
#include <QQuickView>
#include <QUrl>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QVariant>
#include <QQuickItem>
#include <QQuickView>
#include <QObject>
#include <QFontDatabase>
#include <QQmlProperty>
#include <QMetaObject>
#include <keydelegate.h>
#include <QDebug>


VirtualKeyBoardDelegate::VirtualKeyBoardDelegate(QQuickWidget *widget, QWidget* container)
{
    qDebug() << widget;
    int fontId1 = QFontDatabase::addApplicationFont(":/font/fontawesome-4.7.0.ttf");  // :/font/
    int fontId2 = QFontDatabase::addApplicationFont(":/font/consolab.ttf");
    QStringList fontFamilies1 = QFontDatabase::applicationFontFamilies(fontId1);
    qDebug() << "fontFamilies.size() " << fontFamilies1;

    QStringList fontFamilies2 = QFontDatabase::applicationFontFamilies(fontId2);
    qDebug() << "fontFamilies.size() " << fontFamilies2;

    KeyDelegate *pDelegate = new KeyDelegate(this);
    auto engine = widget->engine();
    auto context = engine->rootContext();
    context->setContextProperty("myDelegate", pDelegate);

    widget->setSource(QUrl(QStringLiteral("qrc:/dev.qml"))); // qrc:/
//    widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
    widget->resize(pDelegate->block() * 31, pDelegate->block()*10*pDelegate->rate());
    // set the mainwindow's flag with the following line
    if (container) {
        SetWindowLong((HWND)container->winId(), GWL_EXSTYLE, GetWindowLong((HWND)container->winId(), GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW);
        container->setFixedSize(widget->width(), widget->height());
        container->setMinimumSize(widget->width(), widget->height());
    }
}
